/**
 * Created by MonSterist on 2017/12/8.
 */
angular.module('module.auth')
    .controller('LoginController', LoginController);

LoginController.$inject = ['$scope', '$state', '$cookies', '$rootScope', 'AutherService'];

// 登录
function LoginController($scope, $state, $cookies, $rootScope, AutherService) {
    var vm = this;
    vm.login = login;
    vm.user = {
        "userid": null,
        "password": null
    }
    var curDate = new Date();
    var date = new Date(curDate.getTime() + 24 * 3600 * 1000);


    function login() {
        console.log("1111", vm.user.userid);

        console.log("1111", vm.user.password);

        if (vm.user.userid == null) {
            return alert("请输入账号");
        }
        if (vm.user.password == null) {
            return alert("请输入密码");
        }

        AutherService.checkUser(vm.user.userid, vm.user.password).$promise.then(function (data) {
            userInfo = data;
            $cookies.put("userInfo", JSON.stringify(userInfo), {'expires': date});
            console.log(JSON.parse($cookies.get("userInfo")))
            $state.go('mainpage');
        }, function (err) {
            console.log(err)
            return alert(err.data.msg);
        });
    }


}